/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ecom.shell;

import java.io.PrintStream;
import shell.command.ShellCommandImpl;
import shell.command.ShellContext;

/**
 *
 * @author François
 */
public class OutputCommandImpl extends ShellCommandImpl implements
	EcomShellConstantes {
    /**
     * Constructeur.
     * 
     * @param context
     *            Le contexte
     */
    public OutputCommandImpl(final ShellContext context) {
	super(context);
    }

    /**
     * @see shell.command.ShellCommand#getName()
     */
    @Override
    public String getName() {
	return "output";
    }

    /**
     * @see shell.command.ShellCommand#getUsage()
     */
    @Override
    public String getUsage() {
	return "output [TEXT|XML]";
    }

    /**
     * @see shell.command.ShellCommand#getShortDescription()
     */
    @Override
    public String getShortDescription() {
	return "Sets output; default is TEXT";
    }

    /**
     * @see shell.command.ShellCommandImpl#execute(java.lang.String,
     *      java.io.PrintStream, java.io.PrintStream)
     */
    @Override
    public void execute(final String cmdline, final PrintStream out,
	    final PrintStream err) {
	if (cmdline.isEmpty()) {
	    out.println("Le format d'édition est "
		    + super.getContexte().getVar(
			    EcomShellConstantes.OUTPUT_MIME_FORMAT));
	} else {
	    try {
                String[] arguments = cmdline.split(" ");
                if (arguments[0].equals("TEXT")){
                    getContexte().setVar(EcomShellConstantes.OUTPUT_MIME_FORMAT,
			EcomShellConstantes.TEXT_MIMETYPE);
                }
                if (arguments[0].equals("XML")){
                    getContexte().setVar(EcomShellConstantes.OUTPUT_MIME_FORMAT,
			EcomShellConstantes.XML_MIMETYPE);
                }
	    } catch (final IllegalArgumentException e) {
		out.println("Devise inconnue");
	    }
	}
    }
}

